BrushEdit
Base classes
| Name |
Children |
Inherits |
Widget prettyqt.widgets.widget The base class of all user interface objects. |
|
|
⋔ Inheritance diagram
graph TD
826578002["custom_widgets.BrushEdit"]
3664736470["widgets.Widget"]
829357528["widgets.WidgetMixin"]
3227531497["core.ObjectMixin"]
2751680898["builtins.object"]
625385617["gui.PaintDeviceMixin"]
3620195106["QtWidgets.QWidget"]
3984060476["QtCore.QObject"]
37984305["Shiboken.Object"]
673956333["QtGui.QPaintDevice"]
3664736470 --> 826578002
829357528 --> 3664736470
3227531497 --> 829357528
2751680898 --> 3227531497
625385617 --> 829357528
2751680898 --> 625385617
2751680898 --> 829357528
3620195106 --> 3664736470
3984060476 --> 3620195106
37984305 --> 3984060476
2751680898 --> 37984305
673956333 --> 3620195106
37984305 --> 673956333
🛈 DocStrings
Bases: Widget
Source code in prettyqt/custom_widgets/editors/brushedit.py
| class BrushEdit(widgets.Widget):
value_changed = core.Signal(gui.QBrush)
def __init__(
self,
*args,
color: datatypes.ColorAndBrushType | None = None,
**kwargs,
):
super().__init__(*args, **kwargs)
layout = self.set_layout("horizontal", margin=0)
self.lineedit = widgets.LineEdit()
self.lineedit.set_regex_validator(r"^#(?:[0-9a-fA-F]{6})$")
layout.add(self.lineedit)
action = gui.Action(icon="mdi.format-color-fill", triggered=self.choose_color)
self.button = widgets.ToolButton()
self.button.setDefaultAction(action)
layout.add(self.button)
self._current_brush: gui.QBrush = gui.QBrush(gui.QColor("white"))
if color is not None:
self.set_current_brush(color)
def __repr__(self):
return get_repr(self, self._current_brush)
@core.Slot()
def choose_color(self):
dlg = widgets.ColorDialog()
if self._current_brush:
dlg.setCurrentColor(self._current_brush.color())
if dlg.exec():
new_color = dlg.current_color()
self.set_current_brush(new_color)
self.value_changed.emit(self._current_brush)
def set_current_brush(self, color: datatypes.ColorAndBrushType):
if isinstance(color, gui.QBrush):
self._current_brush = gui.QBrush(color)
else:
self._current_brush = gui.QBrush(colors.get_color(color))
self.lineedit.set_text(self._current_brush.color().name().upper())
icon = iconprovider.for_color(self._current_brush)
self.button.set_icon(icon)
def is_valid(self) -> bool:
return self.lineedit.is_valid()
def get_value(self) -> gui.QBrush:
return gui.QBrush(self._current_brush)
def set_value(self, value: datatypes.ColorAndBrushType):
self.set_current_brush(value)
current_brush = core.Property(
gui.QBrush,
get_value,
set_value,
user=True,
doc="Currently selected Brush",
)
|
:fa-brands-github: Show source on GitHub